import { http } from '@/utils/axios/http'
import { SaveRoleMenuDto, SysRole, SysRoleMenu, SysRolePermission } from './roleTyppe'
const api = http.create({ baseURL: process.env.VITE_APP_CIMS_API })

/**
 * 查询角色列表
 */
const findRoleList = (companyId: string) => {
  return api.get<SysRole[]>('/api/sysRole/findRoleList', { params: { companyId } })
}

/**
 * 保存角色
 */
const saveRole = (params: SysRole) => {
  return api.post('/api/sysRole/saveRole', params)
}

/**
 * 删除角色
 */
const deleteRole = (roleId: string) => {
  return api.post('/api/sysRole/deleteRole', { roleId })
}

/**
 * 查询角色菜单列表
 */
const findRoleMenuList = (roleId: string) => {
  return api.get<SysRoleMenu[]>('/api/sysRole/findRoleMenuList', { params: { roleId } })
}

/**
 * 保存角色菜单
 */
const saveRoleMenu = (params: SaveRoleMenuDto) => {
  return api.post('/api/sysRole/saveRoleMenu', params)
}

/**
 * 新增角色菜单
 */
const addRoleMenu = (params: SysRoleMenu) => {
  return api.post('/api/sysRole/addRoleMenu', params)
}

/**
 * 删除角色菜单
 */
const deleteRoleMenu = (params: SysRoleMenu) => {
  return api.post('/api/sysRole/deleteRoleMenu', params)
}

/**
 * 查询角色权限列表
 */
const findRolePermissionList = (roleId: string, menuId: string) => {
  return api.get<SysRolePermission[]>('/api/sysRole/findRolePermissionList', {
    params: { roleId, menuId }
  })
}

/**
 * 新增角色权限
 */
const addRolePermission = (params: SysRolePermission) => {
  return api.post('/api/sysRole/addRolePermission', params)
}

/**
 * 删除角色权限
 */
const deleteRolePermission = (params: SysRolePermission) => {
  return api.post('/api/sysRole/deleteRolePermission', params)
}

export const roleApi = {
  findRoleList,
  saveRole,
  deleteRole,
  findRoleMenuList,
  saveRoleMenu,
  addRoleMenu,
  deleteRoleMenu,
  findRolePermissionList,
  addRolePermission,
  deleteRolePermission
}
